//
// Created by lymk on 2021/7/31.
//

#ifndef GAME2D_WINDOWSHANDLER_H
#define GAME2D_WINDOWSHANDLER_H

#include <windows.h>
#include <windowsx.h>
#include <cstdint>
#include <string>
#include "InputManager.h"
enum KEY_ACTION{
    NO_ACTION,
    KEY_UP,
    KEY_DOWN,
    KEY_LDRAG,
    KEY_RDRAG,
    KEY_ACTION_MAX
};
class WindowsHandler {
public:
    WindowsHandler();
    WindowsHandler(std::string name,uint32_t height,uint32_t width);

    virtual int Initialize();
    virtual void Finalize();
    // One cycle of the main loop
    virtual void Tick(double DeltaSeconds);
    virtual void Render();
    //Action == 1 up ==0 down
    virtual void HandleKeyInput(u_short keyID,KEY_ACTION Action);
    virtual void HandleMouseInput(u_short keyID,int x,int y,KEY_ACTION Action);

    // the WindowProc function prototype
    static LRESULT CALLBACK WindowProc(HWND hWnd,
                                       UINT message,
                                       WPARAM wParam,
                                       LPARAM lParam);

    inline HWND GetMainWindow() { return m_hWnd; };
    inline HDC GetHDC() {return m_hDc;};

    static bool bShouldClose;

    uint32_t GetWidth() const{return screenWidth;}
    uint32_t GetHeight() const{return screenHeight;}
    void SetWidth(uint32_t Width) {screenWidth = Width;}
    void SetHeight(uint32_t Height) {screenHeight = Height;}
    void SetInputManager(InputManager* manager) {
        inputManager = manager;
    }
    InputManager* GetInputManager() {
        return inputManager;
    }



private:
    HWND m_hWnd;
    HDC m_hDc;
    InputManager* inputManager;
    std::string appName;
    uint32_t screenWidth;
    uint32_t screenHeight;
    bool m_bInLeftDrag = false;
    bool m_bInRightDrag = false;
    int m_iPreviousX = 0;
    int m_iPreviousY = 0;
};


#endif //GAME2D_WINDOWSHANDLER_H
